<template>
    <view class="nav-bar">
        <!-- 返回按钮 -->
		<view class="back-icon" @click="goBack">
		    <text class="iconfont">&#xe600;</text> <!-- 假设使用了 iconfont 字体图标 -->
		</view>

        <!-- 搜索框 -->
        <input 
            class="search-input" 
            placeholder="智能积木 越野四驱车"
            v-model="keyword"
            @confirm="onSearchConfirm"
        />
        
        <!-- 搜索按钮（可选） -->
        <button class="search-button" @click="onSearchConfirm">搜索</button>
    </view>
</template>

<script>
export default {
    data() {
        return {
            keyword: ''
        };
    },
    methods: {
        goBack() {
                uni.reLaunch({
                    url: '/pages/home/home' // 跳转到首页
                });
            },
        onSearchConfirm() {
            if (this.keyword.trim() === "") {
                uni.showToast({
                    title: '关键词不能为空',
                    icon: 'none'
                });
                return;
            }
            // 触发父组件的搜索方法
            this.$emit('search', this.keyword);
        }
    }
};
</script>

<style scoped>
.nav-bar {
    display: flex;
    align-items: center;
    padding: 10px;
    background-color: #FFFFFF;
}

.back-icon {
    width: 20px; /* 设置宽度以确保图标居中 */
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer; /* 鼠标指针变为手型 */
}
.iconfont {
    font-family: "iconfont" !important;
    font-size: 24px;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.search-input {
    flex: 1;
    height: 30px; /* 固定高度 */
    width: 300px; /* 固定宽度 */
    background-color: #F7F7F7;
    border-radius: 4px;
    padding-left: 10px;
    font-size: 16px;
    color: #CCCCCC;
    margin-left: 10px;
}

.search-button {
    margin-left: 10px;
    height: 30px;
    line-height: 30px;
    background-color: #6b8cf7;
    color: white;
    border-radius: 4px;
    padding: 0 15px;
    font-size: 16px;
}
</style>